<?php

ob_start();
echo '<?php' . "\n";
?>
class <?=$this->prefix?>WsdlService{
    var $client;
    var $wsdlUri = '<?=$this->wsdlUri?>';

    public function __construct(){
        $this->client = new nusoap_client($this->wsdlUri, 'wsdl');
    }
        
<?
foreach($operations as $operationName => $operation){
        ?>
        
    public function <?=$operationName?>(<?=implode(", ", $operation['input']['orderedMethodArguments'])?>){
        $params = array(
<?php
    foreach($operation['input']['allElementsRequiredFirst'] as $element){
?>          '<?=$element['name']?>' => $<?=$element['name']?>,
<?php
    }
    ?>
        );

        //Remove all nulls or empty arrays...
        $params = array_filter($params);
        $result = $this->client->call('<?=$operationName?>', $params);
        return $result;
    }
<?php
}
?>
}
<?
$file_contents = ob_get_clean();
$fileHandle = fopen(dirname(dirname(__FILE__)) . '/out/' . $this->prefix . 'WsdlService.php', 'w');
fwrite($fileHandle, $file_contents);
fclose($fileHandle);
?>

